package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.domain.KnowledgeUser;
import com.itheima.domain.PageResult;
import com.itheima.domain.QueryPageBean;
import com.itheima.service.KnowledgeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/Knowledge")
@ResponseBody
public class KnowledgeController {

    @Reference
    private KnowledgeService knowledgeService;


    //评估建议******************************************************
    //分页查询
    @RequestMapping("/findPageAdvice")//分页+，模糊查询
    public PageResult findPageAdvice(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = knowledgeService.pageQueryAdvice(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }

    @RequestMapping("/findByIdAdvice")//根据id查找数据
    @ResponseBody
    public KnowledgeUser findByIdAdvice(Integer LoreID){
        return knowledgeService.findByIdAdvice(LoreID);
    }

    @RequestMapping("/addAdvice")//增
        public void addAdvice(@RequestBody KnowledgeUser knowledgeUser){//增加数据
        System.out.println(knowledgeUser);
        knowledgeService.addAdvice(knowledgeUser);

    }

    @RequestMapping("/updateAdvice")//改
    @ResponseBody
    public void updateAdvice(@RequestBody KnowledgeUser knowledgeUser){//修改数据

        knowledgeService.updateAdvice(knowledgeUser);
    }

    @RequestMapping("/deleteAdvice")//删
    @ResponseBody
    public void deleteAdvice(Integer id){//删除数据
        knowledgeService.deleteAdvice(id);

    }
    //********************************************************************

    //运动项目库++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //分页查询
    @RequestMapping("/findPageSport")//分页+，模糊查询
    public PageResult findPageSport(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = knowledgeService.pageQuerySport(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }

    @RequestMapping("/findByIdSport")//根据id查找数据
    @ResponseBody
    public KnowledgeUser findByIdSport(Integer Number){
        return knowledgeService.findByIdSport(Number);
    }

    @RequestMapping("/addSport")//增
    public void addSport(@RequestBody KnowledgeUser knowledgeUser){//增加数据
        knowledgeService.addSport(knowledgeUser);
    }

    @RequestMapping("/updateSport")//改
    @ResponseBody
    public void updateSport(@RequestBody KnowledgeUser knowledgeUser){//修改数据
        knowledgeService.updateSport(knowledgeUser);
    }

    @RequestMapping("/deleteSport")//删
    @ResponseBody
    public void deleteSport(Integer id){//删除数据
        knowledgeService.deleteSport(id);
    }
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    //膳食库的增删改查-----------------------------------------------------
    //分页查询
    @RequestMapping("/findPage")//分页+，模糊查询
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = knowledgeService.pageQuery(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }

    @RequestMapping("/findById")//根据id查找数据
    @ResponseBody
    public KnowledgeUser findById(Integer FoodID){
        return knowledgeService.findById(FoodID);
    }

    @RequestMapping("/add")//增
    public void add(@RequestBody KnowledgeUser knowledgeUser){//增加数据
        knowledgeService.add(knowledgeUser);
    }

    @RequestMapping("/update")//改
    @ResponseBody
    public void update(@RequestBody KnowledgeUser knowledgeUser){//修改数据
        knowledgeService.update(knowledgeUser);
    }

    @RequestMapping("/delete")//删
    @ResponseBody
    public void delete(Integer id){//删除数据
        knowledgeService.delete(id);
    }
    //-----------------------------------------------------------------

    //项目库的增删改查-----------------------------------------------------
    //分页查询
    @RequestMapping("/findPageItem")//分页+，模糊查询
    public PageResult findPageItem(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = knowledgeService.pageQueryItem(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }

    @RequestMapping("/findByIdItem")//根据id查找数据
    @ResponseBody
    public KnowledgeUser findByIdItem(Integer ItemID){
        return knowledgeService.findByIdItem(ItemID);
    }

    @RequestMapping("/addItem")//增
    public void addItem(@RequestBody KnowledgeUser knowledgeUser){//增加数据
        knowledgeService.addItem(knowledgeUser);
    }

    @RequestMapping("/updateItem")//改
    @ResponseBody
    public void updateItem(@RequestBody KnowledgeUser knowledgeUser){//修改数据
        knowledgeService.updateItem(knowledgeUser);
    }

    @RequestMapping("/deleteItem")//删
    @ResponseBody
    public void deleteItem(Integer ItemID){//删除数据
        knowledgeService.deleteItem(ItemID);
    }
}
